<template>
  <div class="interaction-start">
    <div class="container">
      <div class="box-left">
        <div class="section">
          <div class="case-tip">
            <div class="case-tipName">{{cases.resourceCaseName}}</div>
            <div class="sm-group">
              <el-button type="text" size="mini" icon="el-icon-s-custom">{{cases.resourceGroupName}}</el-button>
              <el-button type="text" size="mini" icon="el-icon-s-grid">{{cases.nodeNum}}个环节</el-button>
            </div>
          </div>
          <div class="case-con">{{cases.caseRequestEn}}</div>
        </div>
        <!--选择班级-->
        <div class="section">
          <div class="case-tip">选择班级</div>
          <div class="list-box">
            <el-checkbox-group v-model="classIds" size="small">
              <el-checkbox :label="item.id" class="inter-checkbox" v-for="(item, index) in classLists" :key="index">{{item.className}}</el-checkbox>
            </el-checkbox-group>
          </div>
        </div>
      </div>
      <div class="box-right">
        <!-- 案例背景 -->
        <div class="case-tip">案例背景</div>
        <el-carousel trigger="click" height="500px" :loop="false">
          <el-carousel-item v-for="(item, index) in cases.resourceCaseBgList" :key="index">
            <!-- 纯文本 -->
            <div class="media-box" v-if="item.displayType === '1'">
              <div class="case-con">{{item.resourceCaseContentEn}}</div>
            </div>
            <!-- 图片 -->
            <div class="media-box" v-if="item.displayType === '2'">
              <img :src="item.fileUrl" style="max-width:100%;max-height:100%;display: block;margin: 0 auto;">
            </div>
            <!-- 音频 -->
            <div class="media-box" v-if="item.displayType === '3'">
              <audio class="audio" controls :src="item.fileUrl"></audio>
            </div>
            <!-- 视频 -->
            <div class="media-box" v-if="item.displayType === '4'">
              <video class="video" controls :src="item.fileUrl">
                <track :src="item.fileUrl" lang="en" label="English" kind="subtitles" default />
              </video>
            </div>
          </el-carousel-item>
        </el-carousel>
        <el-button type="primary" class="inter-btn" @click="trainingInteractionStart" :disabled="btnDisabled" v-if="cases.finishedFlag === '0'">开启互动实训</el-button>
        <el-button type="primary" class="inter-btn" @click="trainingInteractionStart" :disabled="btnDisabled" v-if="cases.finishedFlag === '2'">重新互动实训</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { trainingInteraction, classList, trainingInteractionStart } from '@/api/teacher/manage/trainingInteractionManage'
export default {
  name: 'interactionOpen',
  data () {
    return {
      resourceCaseId: this.$route.query.id,
      cases: {
        nodeNum: '',
        resourceCaseId: '',
        resourceCaseName: '',
        resourceGroupName: '',
        caseRequestCn: '',
        caseRequestEn: '',
        resourceCaseBgList: [],
        finishedFlag: '',
        lessonICaseId: '',
        classNames: '',
        currentCaseNodeName: '',
        isGroup: '',
        stuNo: ''
      },
      classLists: [],
      classIds: [],
      btnDisabled: false
    }
  },
  mounted () {
    this.trainingInteraction()
    this.classList()
  },
  methods: {
    async trainingInteraction () {
      const res = await trainingInteraction({ resourceCaseId: this.resourceCaseId })
      if (res.code === '200') {
        this.cases = res.data
      } else {
        this.$message.error(res.message)
      }
    },
    async classList () {
      const res = await classList({ resourceCaseId: this.resourceCaseId })
      if (res.code === '200') {
        this.classLists = res.data
      } else {
        this.$message.error(res.message)
      }
    },
    async trainingInteractionStart () {
      if (this.classIds.length < 1) {
        this.$message.error('请选择班级')
        return
      }
      this.btnDisabled = true
      const res = await trainingInteractionStart({ classIds: this.classIds, resourceCaseId: this.resourceCaseId })
      if (res.code === '200') {
        this.btnDisabled = false
        this.$message.success('开启互动实训成功!')
        this.$router.go(-1)
      } else {
        this.btnDisabled = false
        this.$message.error(res.message)
      }
    },
    handleDoing () {
      this.$router.push({
        name: 'interactionDoing',
        query: {
          id: this.resourceCaseId
        }
      })
    }
  }
}
</script>
<style scoped lang="scss" rel="stylesheet/scss">
.interaction-start {
  .container {
    display: flex;
    justify-content: space-between;
    .box-left {
      width: 550px;
      background: #fff;
      padding: 15px;
      .section {
        .sm-group{
          margin-top: 10px;
        }
        .train-info {
          color: #BBBBBB;
          font-size: 14px;
          margin-top: 10px;
        }
        .content {
          color: #BBBBBB;
          font-size: 14px;
          padding:20px 0;
          line-height: 1.2;
        }
        .card {
          border-radius: 20px;
          background: #f5f5f5;
          width: 455px;
          margin: 0 auto;
          .row {
            display: flex;
            align-items: center;
            justify-content: space-between;
          }
          .row-1{
            padding: 0 20px;
            line-height: 60px;
            border-bottom: 1px solid #D2D2D2;
          }
          .row-2{
            padding: 0 60px;
            line-height: 50px;
          }
        }
        .list-box {
          margin-top: 20px;
          ul {
            li {
              line-height: 60px;
              font-size: 14px;
              border-bottom: 1px solid #f5f5f5;
              padding: 0 10px;
              position: relative;
              cursor: pointer;
              &:hover {
                background: #f5f5f5;
              }
              .right-arrow {
                position: absolute;
                right: 10px;
              }
            }
          }
        }
      }
    }
    .box-right {
      width: 630px;
      min-height: 100%;
      background: #fff;
      padding: 15px;
      box-sizing: border-box;
      .title {
        font-size: 14px;
        font-weight: bold;
        position: relative;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .tab {
          display: flex;
          .tab-item {
            width: 85px;
            line-height: 40px;
            border: 1px solid #D9D9D9;
            text-align: center;
            font-weight: initial;
            cursor: pointer;
            &.active {
              border: 1px solid #828282;
            }
          }
        }
        .time {
          font-size: 14px;
          color: #828282;
          position: absolute;
          right: 0;
          font-weight: normal;
        }
      }
      .content {
        color:#BBBBBB;
        font-size: 14px;
        padding:20px 0;
        line-height: 1.2;
      }
      .media-box {
        padding: 15px 0;
        .video {
          width: 100%;
        }
      }
      .file-box {
        line-height: 40px;
        display: flex;
        justify-content: space-between;
        border-bottom: 1px solid #f5f5f5;
        font-size: 14px;
        font-weight: bold;
        a {
          color: #009cf6;
          font-weight: normal;
        }
      }
      .fill-box {
        .fill-title {
          font-size: 14px;
        }
        textarea {
          width: 100%;
          margin-top: 20px;
        }
      }
      .report-box {
        li {
          line-height: 70px;
          position: relative;
          .right-arrow {
            position: absolute;
            right: 0;
          }
          textarea {
            width: 100%;
            margin-top: 20px;
          }
        }
      }
      .wait-btn, .submit-btn {
        width: 100%;
        line-height: 40px;
        border-radius: 10px;
        background: #BBBBBB;
        color: #fff;
        text-align: center;
        margin-top: 30px;
        cursor: pointer;
      }
    }
  }
}
.inter-checkbox{
  display: block;
  margin: 15px 0;
  overflow: hidden;
}

  .inter-chooseBox{
    display: flex;
    justify-content: space-between;
    margin: 20px 0;
    padding: 15px;
    border-radius: 10px;
    background: #eee;
  }
  .inter-chooseL{
    width: 320px;
  }
  .inter-className{
    margin-bottom: 10px;
    line-height: 20px;
    font-weight: bold;
  }
  .inter-chooseR{
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    width: 200px;
    text-align: center;
  }
  .inter-tip{
    width: 100%;
    line-height: 18px;
  }
  .inter-histBox{
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    padding: 20px 10px;
    margin: 20px 0;
    cursor: pointer;
  }
  .inter-btn{
    width: 100%;
  }
</style>
